package com.wxl.controller;

import com.wxl.entity.PageResult;
import com.wxl.entity.Result;
import com.wxl.entity.StatusCode;
import com.wxl.pojo.HosInv;
import com.wxl.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/label")
public class BaseController {
    @Autowired
    private BaseService baseService;

    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public List<HosInv> findAll(){
        List<HosInv> hosInvList = baseService.findAll();
        return hosInvList;
    }

    @RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.POST)
    public Result pageQuery(@RequestBody HosInv hosInv, @PathVariable int page, @PathVariable int size){
        Page<HosInv> pageData = baseService.pageQuery(hosInv, page, size);
        return new Result(true, StatusCode.OK, "查询成功", new PageResult<HosInv>(pageData.getTotalElements(), pageData.getContent()));
    }

    @RequestMapping(method = RequestMethod.POST)
    public Result save(@RequestBody HosInv hosInv){
        baseService.save(hosInv);
        return new Result(true, StatusCode.OK, "添加成功");
    }

    @RequestMapping(value = "/{inv_aid}", method = RequestMethod.DELETE)
    public Result delete(@PathVariable int inv_aid){
        baseService.deleteById(inv_aid);
        return new Result(true, StatusCode.OK, "删除成功");
    }



}
